package com.rms.hkpc.dialog;

import android.content.Context;
import android.view.View;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;

import com.rms.hkpc.R;
import com.rms.hkpc.activity.AddHocOtherActivity;
import com.rms.hkpc.constant.AllConstants;
import com.rms.hkpc.util.SPUtil;

public class ResultDialog extends BaseDialog {

    private Context context;
    private int result;

    public ResultDialog(@NonNull Context context,int result, IDoneListener iDoneListener) {
        super(context, R.style.toast_dialog);
        this.context = context;
        this.result = result;
        this.iDoneListener = iDoneListener;
    }

    @Override
    public void refreshView() {

    }

    @Override
    public void initView() {
        RadioGroup rg = findViewById(R.id.rg_status);
        if (context instanceof AddHocOtherActivity) {
            rg.getChildAt(0).setVisibility(View.GONE);
            rg.check(result == 1?R.id.rb_success:R.id.rb_fail);
        }else {
            rg.check(result == 0 ? R.id.rb_fail : result == 1 ? R.id.rb_success : R.id.rb_all);
        }
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_success) {
                    iDoneListener.getDoneFromDialog(R.string.success, 1);
                } else if (checkedId == R.id.rb_fail) {
                    iDoneListener.getDoneFromDialog(R.string.fail, 0);
                } else {
                    iDoneListener.getDoneFromDialog(R.string.all, 2);
                }
                dismiss();
            }
        });
    }

    @Override
    public int getLayoutId() {
        return R.layout.dialog_result;
    }

    private IDoneListener iDoneListener;

    public interface IDoneListener {
        void getDoneFromDialog(int str, int resultId);
    }
}
